package com.crm.util;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class Encrypter {
	
	public static String md5(String s){
		
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			sun.misc.BASE64Encoder encoder = new BASE64Encoder();
			return encoder.encode(md.digest(s.getBytes("utf8")));
			
			
			
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return s;
		
		
		
		
		
		
		
	}
public static String remd5(String s){
		
		
			try {
				MessageDigest md = MessageDigest.getInstance("MD5");
				sun.misc.BASE64Decoder bd = new BASE64Decoder();
				return bd.decodeBuffer(md.digest(s.getBytes()).toString()).toString();
			} catch (NoSuchAlgorithmException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
		
	
		
		
		return s;
		
		
		
		
		
		
		
	}
	
	
	
	
	
	
	public static void main(String[] args){
		System.out.println("admin加密后"+Encrypter.md5("admin"));
		System.out.println("admin解密后"+Encrypter.remd5(Encrypter.md5("admin")));
		
		
		
		System.out.println("123456加密后"+Encrypter.md5("123456"));
		System.out.println("123456解密后"+Encrypter.remd5(Encrypter.md5("123456")));

		
	
		
		
	}
	
	
	
	
	
	
	
	
}
